import java.io.*;
import java.util.Scanner;

public class UseDelimiterExample{
  public static void main(String[ ] args) throws IOException {
     Scanner scanner = new Scanner(System.in);
     FileInputStream infile = new FileInputStream("input.txt");
     
     Scanner fscanner = new Scanner(infile);
     fscanner.useDelimiter("[ \n\t\r?:.,;!]+");
     //fscanner.useDelimiter("[\\s?:.,;!]+");
     
     String word1, word2 = "";
     System.out.println("Enter word to search for: ");
     word1 = scanner.next( );
     
     int count = 0;
     while(fscanner.hasNext( )){
       word2 = fscanner.next( );
       if(word1.equals(word2))
       	   count++;  
     }
     
     if(count == 0)
     	System.out.println("The word: " + word1 + " is not in the file");
     else
     	System.out.println("The frequency of the word: " + word1 + " is " + count);

     fscanner.close();
  }
}

